<template>
    <div>
        <el-button class="right" @click="randomPaper">
            <i class="el-icon-refresh"></i>
            随机来一题
        </el-button>
        <el-table 
        :data="paperData"
        v-loading='table_loading'
        :default-sort="{prop: 'name', order: 'descending'}">
            <el-table-column label="试卷名" prop="name">
                <template slot-scope="scope">
                    <router-link :to="{name: 'answer',params: {paperId:scope.row['id']}}">{{ scope.row.name }}</router-link>
                </template>
            </el-table-column>
            <el-table-column
            prop="groupName"
            label="等级"
            sortable
            ></el-table-column>
            <el-table-column prop="gradeName" label="年级" sortable></el-table-column>
            <el-table-column prop="subject" label="科目" sortable></el-table-column>
            <el-table-column prop="lastModifiedDate" label="时间" sortable></el-table-column>
        </el-table>
    </div>
</template>
<script>
import { find_exam_list } from "@/api/question_bank";
export default {
    name: "ChoicePaper",
    data() {
        return {
            paperData: [],
            table_loading: false
        };
    },
    methods: {
        randomPaper () {
            let index = Math.floor(Math.random()*this.paperData.length);
            console.log(index)
            let paperId = this.paperData[index]['id'];
            this.$router.push({name: 'answer',params: {paperId}});
        }
    },
    mounted() {
        this.table_loading = true;
        find_exam_list({
            // tenantId:"754498800554344448"
        }).then((res) => {
            this.paperData = res.data.data;
            this.table_loading = false;
        });
    },
};
</script>
<style scoped>
a {
    color: blue;
    text-decoration: blue!important;
}
</style>